package com.sgy.springboot_demo.controller;

import com.sgy.springboot_demo.pojo.Employee;
import com.sgy.springboot_demo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/getEmpById/{id}")
    public Employee getEmpById(@PathVariable("id") Integer id){
        return employeeService.getEmpById(id);
    }

    @RequestMapping("/updateEmp/{id}")
    public Employee updateEmp(@PathVariable("id") Integer id) {
        Employee empById = employeeService.getEmpById(id);
        empById.setLastName("sgy");
        employeeService.updateEmp(empById);
        return employeeService.getEmpById(id);
    }

    @RequestMapping("/delEmp/{id}")
    public Employee delEmp(@PathVariable("id") Integer id) {
        employeeService.delEmp(id);
        return null;
    }
}
